Refactor AnimatedContent: custom scroller support, safer cleanup & exit animations #723
+273
−106
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since I use AnimatedContent in my projects, I have been modifying the component to suit my needs as I use it. For this reason, I decided to make this pull request, as I believe that enough has been fixed and added that beginners would really need
KEY CHANGES
Safe Cleanup
Before: The component used
ScrollTrigger.getAll().forEach(t => t.kill())on unmount. This killed ALL scroll triggers on the page, breaking animations in other componentsAfter: Now correctly stores references to the specific timeline and trigger instance, killing only its own processes
Custom Scroller Support
Added logic to detect specific scroll containers (via container prop or snap-main-container id)
Essential for layouts using overflow: scroll, CSS Scroll Snap, or third-party scroll libraries where the window is not the scroller
Exit Animations
Introduced disappearAfter, disappearDuration, and disappearEase props. Elements can now animate out automatically after the entry animation completes
Technical
Switched from
gsap.totogsap.timelinefor better control over animation sequencing (Entry -> Delay -> Exit).Testing